package com.xiweicheng.test.proxy;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@SpringBootApplication
@Controller
public class Application {

	public static void main(String[] args) {
		SpringApplication.run(Application.class, args);
	}

	@GetMapping("")
	@ResponseBody
	public String home(HttpServletRequest req, HttpServletResponse resp) throws IOException {

		return ProxyUtil.proxy(req, resp);

	}

	@RequestMapping("**")
	@ResponseBody
	public void forward(HttpServletRequest req, HttpServletResponse resp, @RequestBody(required = false) String body)
			throws IOException {

		ProxyUtil.forward(req, resp, body);

	}

}
